package com.ac.input.web.action.input;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.caac.core.util.Page;
import com.caac.core.web.action.BasePageViewAction;
import com.caac.core.web.action.PageViewForward;
import com.caac.core.web.form.BaseForm;
import com.ac.input.dao.BaseDao;
import com.ac.input.dao.ReportsDao;
import com.ac.input.web.form.ListSearchForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:lianzs@tom.com">Lianzs</a>
 * @version 1.0
 */

public class SearchListAction extends BasePageViewAction {

    protected PageViewForward doPageViewExecute(ActionMapping mapping,
                                                BaseForm form,
                                                HttpServletRequest request,
                                                HttpServletResponse response,
                                                int pageNo, int pageSize) throws
            Exception {
        ListSearchForm myForm = (ListSearchForm) form;
        if (myForm.isFirst()) {
            ReportsDao rpsDao = (ReportsDao)this.getBean("reportsDao");
            myForm.setDm(rpsDao.getHndInpDefItm(myForm.getMendId(), myForm
                    .getColId()));
            myForm.setFirst(false);
        }

        String sql = myForm.getDm().getListSql();
        String whereStr = myForm.getWhereStr();
        String orderStr = "";
        String viewStr = "*";
        BaseDao baseDao = (BaseDao)this.getBean("hndBaseDao");
        Page page = new Page(baseDao.getCount(sql, whereStr), pageNo,
                             pageSize);
        List dmList = baseDao.getObjects(sql, viewStr, whereStr, orderStr,
                                              page);

        return new PageViewForward(forward(mapping), dmList, page, null, null,
                                   null);
    }
}
